Ext.define('Seq.pivot.plugin.Exporter', {
    override: 'Ext.pivot.plugin.Exporter',

    getColumnHeaders: function (columns, config) {
        let cols = [], length = columns.length, i, obj, col, doExtract;
        for (i = 0; i < length; i++) {
            col = columns[i];
            doExtract = this.onlyExpandedNodes ? (!col.group || col.group.expanded || (!col.group.expanded && col.subTotal)) : true;
            if (doExtract && !col.subTotal) { // 不导出小节
                obj = {
                    text: (col.subTotal && col.group && col.group.expanded ? col.group.getTextTotal() : col.text)
                };
                if (col.columns) {
                    obj.columns = this.getColumnHeaders(col.columns, config);
                } else {
                    obj.width = col.dimension ? col.dimension.getWidth() * 1.5 : col.width * 1.5 || 140; // 增加列宽
                    obj.style = col.dimension ? this.getExportStyle(col.dimension.getExportStyle(), config) : null;
                }
                cols.push(obj);
            }
        }
        return cols;
    },

    getDataIndexColumns: function (columns) {
        let cols = [], i, col, doExtract;
        for (i = 0; i < columns.length; i++) {
            col = columns[i];
            doExtract = this.onlyExpandedNodes ? (!col.group || col.group.expanded || (!col.group.expanded && col.subTotal)) : true;
            if (doExtract && !col.subTotal) { // 不导出小节

                if (col.dataIndex) {
                    cols.push({
                        dataIndex: col.dataIndex,
                        agg: col.dimension ? col.dimension.getId() : null
                    });
                } else if (col.columns) {
                    Ext.Array.insert(cols, cols.length, this.getDataIndexColumns(col.columns));
                }
            }
        }
        return cols;
    }

});
